import { Req, type Resp } from '@/utils/request'

// 获取菜单
export function getMenuTree(): Promise<Resp<Menu[]>> {
  return Req.$get<Menu[]>('/system/menu/menuTree')
}

// 添加菜单
export function addMenu(menu: Menu): Promise<Resp<any>> {
  return Req.$post<any>('/system/menu/addMenu', menu)
}

// 更新菜单
export function updateMenu(menu: Menu): Promise<Resp<any>> {
  return Req.$put<any>('/system/menu/updateMenu', menu)
}

// 删除菜单
export function deleterMenu(id: number): Promise<Resp<any>> {
  return Req.$delete<any>('/system/menu/deleteMenu', undefined, { id })
}

// 获取权限列表
export function getPermsList(id: number): Promise<Resp<Menu[]>> {
  return Req.$get<Menu[]>('/system/menu/permList', { id })
}

// 添加菜单
export function addPerm(perm: {
  parentId: number
  menuName: string
  permission: string
}): Promise<Resp<any>> {
  return Req.$post<any>('/system/menu/addPerm', perm)
}

// 更新菜单
export function updatePerm(perm: {
  id: number
  menuName: string
  permission: string
}): Promise<Resp<any>> {
  return Req.$post<any>('/system/menu/updatePerm', perm)
}

// 获取菜单图标
export function getMenuIcons(): Promise<Resp<Menu[]>> {
  return Req.$get<Menu[]>('/system/menu/icons')
}
